package com.asktgapp.user.fragment;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.view.ViewPager;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.asktgapp.MyConstant;
import com.asktgapp.R;
import com.asktgapp.base.BaseFragment;
import com.asktgapp.model.DeviceTypeVO;
import com.sina.weibo.sdk.web.param.DefaultWebViewRequestParam;

import butterknife.ButterKnife;
import butterknife.InjectView;

/**
 * time:2018/2/24
 * Create By ZhaoKai
 * Email: dczk@foxmail.com
 * Description:
 */

public class MyPublishFragment extends BaseFragment {
    @InjectView(R.id.tablayout)
    TabLayout mTabLayout;
    @InjectView(R.id.viewpager)
    ViewPager mViewPager;
    private static final int PAGE_COUNT = 5;

    private TabAdapter mAdapter;

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        ViewGroup viewGroup = (ViewGroup) inflater.inflate(R.layout.fragment_my_publish, container, false);
        ButterKnife.inject(this, viewGroup);
        return super.onCreateView(inflater, viewGroup, savedInstanceState);
    }

    @Override
    protected void initView(View rootView) {
        getBaseActivity().setBackNavigationIcon();
        mAdapter = new TabAdapter(getFragmentManager());
        mViewPager.setOffscreenPageLimit(3);
        mViewPager.setAdapter(mAdapter);
        mTabLayout.setupWithViewPager(mViewPager);
    }

    @Override
    public void loadData() {

    }

    @Override
    public void onDestroyView() {
        super.onDestroyView();
        ButterKnife.reset(this);
    }

    public class TabAdapter extends FragmentPagerAdapter {

        public TabAdapter(FragmentManager fm) {
            super(fm);
        }

        @Override
        public Fragment getItem(int position) {
            int type;
            switch (position) {
                case 0:
                    type = MyConstant.TYPE_ALL;
                    break;
                case 1:
                    type = MyConstant.TYPE_USED;
                    break;
                case 2:
                    type = MyConstant.TYPE_RENT;
                    break;
                case 3:
                    type = MyConstant.TYPE_QIUZHU;
                    break;
//                case 4:
//                    type = MyConstant.TYPE_USED_CHECK;
//                    break;
//                case 5:
//                    type = MyConstant.TYPE_HELP_CHECK;
//                    break;
                case 4:
                    type = MyConstant.TYPE_FREE_ASK;
                    break;
                default:
                    type = MyConstant.TYPE_ALL;
                    break;
            }
            return MyPublishItemFragment.newInstance(type);
        }

        @Override
        public int getCount() {
            return PAGE_COUNT;
        }

        @Override
        public CharSequence getPageTitle(int position) {
            switch (position) {
                case 0:
                    return "全部";
                case 1:
                    return getString(R.string.homePage_used_machine);
                case 2:
                    return "设备出租";
                case 3:
                    return "设备求租";
//                case 4:
//                    return getString(R.string.homePage_used_check);
//                case 5:
//                    return getString(R.string.homePage_problem_check);
                case 4:
                    return getString(R.string.free_ask);
                default:
                    return "全部";
            }
        }
    }
}
